package utility;

import java.io.*;

import com.thoughtworks.xstream.io.*;
import com.thoughtworks.xstream.io.xml.*;

public class XmlWriter implements HierarchicalStreamWriter {
   private HierarchicalStreamWriter writer;
   
   public XmlWriter (OutputStream out) {
      try {
         writer = new PrettyPrintWriter(new OutputStreamWriter(out, "UTF-8"));
      } 
      catch (UnsupportedEncodingException e) {
         writer = new PrettyPrintWriter(new OutputStreamWriter(out));
      }
   }

   @Override
   public void startNode(String name) {
//      System.out.println("ExiWriter.startNode (" + name + ")");
      writer.startNode(name);
   }

   @Override
   public void addAttribute(String name, String value) {
//      System.out.println("ExiWriter.addAttribute (" + name + ", " + value + ")");
      writer.addAttribute(name, value);
   }

   @Override
   public void setValue(String text) {
//      System.out.println("ExiWriter.setValue (" + text + ")");
      writer.setValue(text);
   }

   @Override
   public void endNode() {
//      System.out.println("ExiWriter.endNode()");
      writer.endNode();
   }

   @Override
   public void flush() {
//      System.out.println("ExiWriter.flush()");
      writer.flush();
   }

   @Override
   public void close() {
//      System.out.println("ExiWriter.close()");
      writer.close();
   }

   @Override
   public HierarchicalStreamWriter underlyingWriter() {
//      System.out.println("ExiWriter.underlyingWriter()");
      return writer.underlyingWriter();
   }    
}
